/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.ad.entity;

import java.util.Date;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.common.utils.excel.annotation.ExcelField;
import com.jeesite.common.utils.excel.annotation.ExcelField.Align;
import com.jeesite.common.utils.excel.annotation.ExcelFields;
import com.jeesite.common.utils.excel.fieldtype.AreaType;
import com.jeesite.modules.sys.entity.Area;

/**
 * 广告Entity
 *
 * @author chenxm
 * @version 2019-04-17
 */
@Table(name = "ad", alias = "a", columns = {
        @Column(name = "id", attrName = "id", label = "ID", isPK = true),
        @Column(name = "name", attrName = "name", label = "广告名称", queryType = QueryType.LIKE),
        @Column(name = "terminal", attrName = "terminal", label = "投放终端"),
        @Column(name = "type", attrName = "type", label = "广告类型"),
        @Column(name = "shape", attrName = "shape", label = "广告形式"),
        @Column(name = "url_type", attrName = "urlType", label = "落地页形式"),
        @Column(name = "url", attrName = "url", label = "url"),
        @Column(includeEntity = DataEntity.class),
        @Column(name = "vertiser_id", attrName = "vertiserId", label = "广告主"),
        @Column(name = "media_name", attrName = "mediaName", label = "投放媒体", queryType = QueryType.LIKE),
        @Column(name = "media_url", attrName = "mediaUrl", label = "媒体页URL"),
        @Column(name = "ad_location_id", attrName = "adLocationId", label = "广告位ID"),
        @Column(name = "ad_exposure_num", attrName = "adExposureNum", label = "广告页曝光量", comment = "广告页曝光量（千次）"),
        @Column(name = "ad_click_num", attrName = "adClickNum", label = "广告页点击量"),
        @Column(name = "ad_click_rate", attrName = "adClickRate", label = "广告页点击率"),
        @Column(name = "ld_show_num", attrName = "ldShowNum", label = "落地页展示量"),
        @Column(name = "delivery_start_time", attrName = "deliveryStartTime", label = "投放开始时间"),
        @Column(name = "delivery_end_time", attrName = "deliveryEndTime", label = "投放结束时间"),
		@Column(name="area_code", attrName="areaCode.areaCode", label="投放地域", comment="投放地域"),
}, joinTable = {
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = AdVertiser.class, attrName = "adVertiser", alias = "u10",
                on = "u10.id = a.vertiser_id", columns = {
                @Column(name = "id", label = "ID", isPK = true),
                @Column(name = "account", label = "账户名称", isQuery = false),
        }),

		@JoinTable(type=Type.LEFT_JOIN, entity=Area.class, alias="ar",
			on="ar.area_code = a.area_code", attrName="areaCode",
			columns={@Column(includeEntity=Area.class)}),
}, orderBy = "a.update_date DESC",extWhereKeys="data_power"
)
public class Ad extends DataEntity<Ad> {
    @Valid
    @ExcelFields({
    		@ExcelField(title = "广告计划名称", attrName = "name", align = ExcelField.Align.CENTER, sort = 10),
            @ExcelField(title = "投放终端", attrName = "terminal", align = ExcelField.Align.CENTER, sort = 20, dictType = "ad_terminal"),
            @ExcelField(title = "广告类型", attrName = "type", align = ExcelField.Align.CENTER, sort = 30, dictType = "ad_type"),
            @ExcelField(title = "广告形式", attrName = "shape", align = ExcelField.Align.CENTER, sort = 40, dictType = "ad_shape"),
            @ExcelField(title = "落地页形式", attrName = "urlType", align = ExcelField.Align.LEFT, sort = 50, dictType = "ad_url_type"),
            @ExcelField(title = "落地页URL", attrName = "url", align = ExcelField.Align.CENTER, sort = 60),
	        @ExcelField(title = "广告主", attrName = "adVertiser.account", align = ExcelField.Align.CENTER, sort = 70),
            @ExcelField(title = "投放媒体", attrName = "mediaName", align = ExcelField.Align.CENTER, sort = 80),
            @ExcelField(title = "媒体页URL", attrName = "mediaUrl", align = ExcelField.Align.CENTER, sort = 90),
            @ExcelField(title = "广告位ID", attrName = "adLocationId", align = ExcelField.Align.CENTER, sort = 100),
            @ExcelField(title = "广告页曝光量", attrName = "adExposureNum", align = ExcelField.Align.CENTER, sort = 110),
            @ExcelField(title = "广告页点击量", attrName = "adClickNum", align = ExcelField.Align.CENTER, sort = 120),
            @ExcelField(title = "广告页点击率", attrName = "adClickRate", align = ExcelField.Align.CENTER, sort = 130),
            @ExcelField(title = "落地页展示量", attrName = "ldShowNum", align = ExcelField.Align.CENTER, sort = 140),
            @ExcelField(title = "获客数量", attrName = "guestNum", align = ExcelField.Align.CENTER, sort = 150),
            @ExcelField(title = "投放开始时间", attrName = "deliveryStartTime", align = ExcelField.Align.CENTER, sort = 160, dataFormat = "yyyy-MM-dd"),
            @ExcelField(title = "投放结束时间", attrName = "deliveryEndTime", align = ExcelField.Align.CENTER, sort = 170, dataFormat = "yyyy-MM-dd"),
			@ExcelField(title = "投放地域", attrName = "areaCode", align = Align.CENTER, sort = 180, fieldType=AreaType.class,width=25*256)
    })

    private static final long serialVersionUID = 1L;
    private String name;        // 广告名称
    private String terminal;        // 投放终端
    private String type;        // 广告类型
    private String shape;        // 广告形式
    private String urlType;        // 落地页形式
    private String url;        // url
    private String vertiserId;        // 广告主
    private AdVertiser adVertiser;        // 广告主

    private String mediaName;        // 投放媒体
    private String mediaUrl;        // 媒体页URL
    private String adLocationId;        // 广告位ID
    private String adExposureNum;        // 广告页曝光量（千次）
    private String adClickNum;        // 广告页点击量
    private String adClickRate;        // 广告页点击率
    private String ldShowNum;        // 落地页展示量
    private Date deliveryStartTime;        // 投放开始时间
    private Date deliveryEndTime;        // 投放结束时间
    private Area areaCode;        // 投放地域

    private Integer guestNum;//获客数量

    private String userRole; //登录用户角色

    public Ad() {
        this(null);
    }

	public Ad(String id){
		super(id);
	}

	public Date getDeliveryStartTime() {
		return deliveryStartTime;
	}

	public void setDeliveryStartTime(Date deliveryStartTime) {
		this.deliveryStartTime = deliveryStartTime;
	}

	public Date getDeliveryEndTime() {
		return deliveryEndTime;
	}

	public void setDeliveryEndTime(Date deliveryEndTime) {
		this.deliveryEndTime = deliveryEndTime;
	}

	@NotNull(message="所属地区不能为空")
	public Area getAreaCode() {
		if (areaCode == null){
			areaCode = new Area();
		}
		return areaCode;
	}

	public void setAreaCode(Area areaCode) {
		this.areaCode = areaCode;
	}

	@Length(min = 0, max = 200, message = "广告名称长度不能超过 200 个字符")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Length(min = 0, max = 1, message = "投放终端长度不能超过 1 个字符")
    public String getTerminal() {
        return terminal;
    }

    public void setTerminal(String terminal) {
        this.terminal = terminal;
    }

    @Length(min = 0, max = 1, message = "广告类型长度不能超过 1 个字符")
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Length(min = 0, max = 1, message = "广告形式长度不能超过 1 个字符")
    public String getShape() {
        return shape;
    }

    public void setShape(String shape) {
        this.shape = shape;
    }

    @Length(min = 0, max = 1, message = "落地页形式长度不能超过 1 个字符")
    public String getUrlType() {
        return urlType;
    }

    public void setUrlType(String urlType) {
        this.urlType = urlType;
    }

    @Length(min = 0, max = 255, message = "url长度不能超过 255 个字符")
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Length(min = 0, max = 64, message = "广告主长度不能超过 64 个字符")
    public String getVertiserId() {
        return vertiserId;
    }

    public void setVertiserId(String vertiserId) {
        this.vertiserId = vertiserId;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public AdVertiser getAdVertiser() {
        return adVertiser;
    }

    public void setAdVertiser(AdVertiser adVertiser) {
        this.adVertiser = adVertiser;
    }

    public String getUserRole() {
        return userRole;
    }

    public void setUserRole(String userRole) {
        this.userRole = userRole;
    }

    public Integer getGuestNum() {
        return guestNum;
    }

    public void setGuestNum(Integer guestNum) {
        this.guestNum = guestNum;
    }

    @Length(min = 0, max = 255, message = "投放媒体长度不能超过 255 个字符")
    public String getMediaName() {
        return mediaName;
    }

    public void setMediaName(String mediaName) {
        this.mediaName = mediaName;
    }

    @Length(min = 0, max = 255, message = "媒体页URL长度不能超过 255 个字符")
    public String getMediaUrl() {
        return mediaUrl;
    }

    public void setMediaUrl(String mediaUrl) {
        this.mediaUrl = mediaUrl;
    }

    @Length(min = 0, max = 255, message = "广告位ID长度不能超过 255 个字符")
    public String getAdLocationId() {
        return adLocationId;
    }

    public void setAdLocationId(String adLocationId) {
        this.adLocationId = adLocationId;
    }

    @Length(min = 0, max = 255, message = "广告页曝光量长度不能超过 255 个字符")
    public String getAdExposureNum() {
        return adExposureNum;
    }

    public void setAdExposureNum(String adExposureNum) {
        this.adExposureNum = adExposureNum;
    }

    @Length(min = 0, max = 255, message = "广告页点击量长度不能超过 255 个字符")
    public String getAdClickNum() {
        return adClickNum;
    }

    public void setAdClickNum(String adClickNum) {
        this.adClickNum = adClickNum;
    }

    @Length(min = 0, max = 255, message = "广告页点击率长度不能超过 255 个字符")
    public String getAdClickRate() {
        return adClickRate;
    }

    public void setAdClickRate(String adClickRate) {
        this.adClickRate = adClickRate;
    }

    @Length(min = 0, max = 255, message = "落地页展示量长度不能超过 255 个字符")
    public String getLdShowNum() {
        return ldShowNum;
    }

    public void setLdShowNum(String ldShowNum) {
        this.ldShowNum = ldShowNum;
    }

    public void setAd_id_gte() {
        if (StringUtils.isNotEmpty(this.id)) {
            sqlMap.getWhere().and("id", QueryType.GTE, this.id);
        }

    }
}